package com.boot.security.server.dao.mffl;

import com.boot.security.server.model.mffl.MfflChatContent;
import com.boot.security.server.model.mffl.Vo.MfflChatContentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface MfflChatContentDao {

    @Select("select * from mffl_chat_content t where t.id = #{id}")
    MfflChatContent getById(Long id);

    @Delete("delete from mffl_chat_content where id = #{id}")
    int delete(Long id);

    int update(MfflChatContent mfflChatContent);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_chat_content(send_id, receive_id, content, createTime, updateTime, deleteTime, mapping_id, state) values(#{sendId}, #{receiveId}, #{content}, now(), now(), now(), #{mappingId}, #{state})")
    int save(MfflChatContent mfflChatContent);

    int count(@Param("params") Map<String, Object> params);

    List<MfflChatContent> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //图文资讯-查询消息记录
    List<MfflChatContentVo> getChatRecordList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    int getChatRecordCount(@Param("params") Map<String, Object> params);

    //图文资讯-修改消息为已读
    @Update("update mffl_chat_content set status = 0 where mapping_id = #{mapping_id}")
    void updateStatus(@Param("mapping_id") Long mapping_id);

    @Select("select count(*) from mffl_chat_content where send_id = #{sendId} and receive_id = #{receiveId} and status = 1")
    Integer getChatCountByMappingId(@Param("sendId") Integer sendId,@Param("receiveId") Integer receiveId);
}
